package com.zyw.customcalendar.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;

/**
 * Created by zyw on 2017/9/6.
 */
public class CusViewPager extends ViewPager {
    private CalendarView mCusView = null;

    public CusViewPager(Context context) {
        super(context);
    }

    public CusViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        // find the current child view
        for (int i = 0; i < getChildCount(); i++) {
            mCusView = (CalendarView) getChildAt(i);
            if("true".equals(mCusView.getTag())){
                break;
            }
        }

        if (mCusView != null) {
            setMeasuredDimension(getMeasuredWidth(), (mCusView.cHeight != 0) ? mCusView.cHeight : mCusView.getMeasuredHeight());
            return;
        }

        setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());
    }

    public CalendarView getCurrentView() {
        return mCusView;
    }
}
